#!/bin/bash

# 检查是否传入了年份参数
if [ -z "$1" ]; then
  echo "Usage: $0 <year>"
  exit 1
fi

# 获取年份参数
year=$1

# 输出文件名称
output_file="urls/gharchive_urls_${year}.txt"

# 清空或创建输出文件
> "$output_file"

# 生成月份、日期和小时的URL列表并写入文件
for month in {01..12}; do
  # 计算当月天数
  days_in_month=$(cal $month $year | awk 'NF {DAYS = $NF}; END {print DAYS}')
  
  for day in $(seq -w 01 $days_in_month); do
    for hour in {0..23}; do
      echo "https://data.gharchive.org/$year-$month-$day-$hour.json.gz" >> "$output_file"
    done
  done
done

echo "URL列表已生成并保存到 $output_file"
